﻿Chenxin.UI.WorkReportDetailInfo = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/WorkReportDetailInfo.ashx',
    createGrid: function() {
        return new Chenxin.UI.Pagination({
            actionUrl: this.actionUrl,
            id: 'replyGrid',
            renderTo: 'divreplytable',
            pageSize: 10,
            data: { op: 'getreply', recordid: $("#ctl00_main_hidRecordId").val(), rootid: $("#ctl00_main_hidRootId").val() }
        });
    },
    initEvent: function() {
        var _this = this;

        _this.editor = $('#txtcontent').xheditor();

        _this.isclick = true;

        //我要回复点击事件
        $('#btn_reply').live('click', function() {
            $("#divreply").slideToggle("slow");
        });

        var hasFile = false;
        //上传附件Flash
        $("#thumbnialUploadify").uploadify({
            uploader: '/js/uploadify.swf',
            script: '/service/WorkReportDetailInfo.ashx?op=fileupload',
            cancelImg: '/images/cancel.png',
            buttonImg: '/images/fileupload.png',
            auto: false,
            multi: false,
            sizeLimit: 1048576,
            height: 24,
            width: 190,
            wmode: 'transparent',
            onClick: function() {
                if (!hasFile) {
                    _this.isclick = false;
                }
            },
            onSelectCancel: function() {
                if (!hasFile) {
                    _this.isclick = true;
                }
            },
            onSelect: function(event, queueID, fileObj) {
                hasFile = true;
            },
            onComplete: function(event, queueID, fileObj, response, data) {
                if (response) {
                    try {
                        eval("var json=" + response);
                        if (json.success == 1) {
                            if (data.fileCount == 0) {
                                _this.addreply(json.data.filename, json.data.savename);
                                _this.isclick = true;
                                hasFile = false;
                            }
                        } else if (json.success == 0) {
                            alert(json.msg);
                        } else {
                            alert(json.msg);
                            window.location.href = Chenxin.loginUrl;
                        }
                    } catch (e) {
                        alert('返回数据格式错误，文件上传失败！');
                    }
                }
            },
            onError: function(event, queueID, fileObj, errorObj) {
                alert("文件:" + fileObj.name + "上传失败(" + errorObj.info + ")");
            },
            onCancel: function(event, queueID, fileObj) {
                _this.isclick = true;
                hasFile = false;
            }
        });

        $('#btn_addreply').live('click', function() {

            if ($("#txtSubject").val().isBlank()) {
                alert('请填写回复主题！');
                return;
            }
            if ($("#txtcontent").val().isBlank()) {
                alert('请填写回复正文！');
                return;
            }
            $("#thumbnialUploadify").uploadifyUpload();
            if (_this.isclick && !hasFile) {
                _this.addreply('', '');
            }
        });

        //编辑
        $('#btn_edit').live('click', function() {
            Chenxin.Fn.checkPermit(_this.actionUrl, 'editreply', function(data, msg) {
                if (data.permit != undefined) {
                    _this.permit = data.permit;
                }
            }, this);
            if (_this.permit) {
                window.location.href = "/WorkReport/WorkReportSend.aspx?RecordId=" + this.name + "";
            } else {
                alert('您没有此权限，请联系管理员！');
            }

        });

        //删除
        $('#btn_del').live('click', function() {
            Chenxin.ajax({
                type: "post",
                dataType: "json",
                async: false,
                url: _this.actionUrl,
                data: { op: 'delreply', recordid: this.name },
                onSuccess: function(data, msg) {
                    alert(msg);
                    window.location.href = "/WorkReport/WorkReportSearch.aspx";
                }
            });

        });

        //转发
        $("#btn_transmit").live("click", function() {
            window.location.href = "/WorkReport/WorkReportSend.aspx?RelationId=" + this.name + "";
        });

        //复制回复
        $("A[name='btn_copyreply']").live("click", function() {
            if (window.clipboardData) {
                var strContent = $(this).parents("tr:eq(0)").children("td:eq(1)").find("span:eq(0)").text();
                window.clipboardData.setData("Text", strContent);
                alert("已复制到剪切板");
            } else {
                alert("此浏览器不支持此功能");
            }
        });

        //复制正文
        $("#btn_copycon").live("click", function() {
            if (window.clipboardData) {
                var strContent = $(this).parents("tr:eq(0)").children("td:eq(1)").find("span:eq(0)").text();
                window.clipboardData.setData("Text", strContent);
                alert("已复制到剪切板");
            } else {
                alert("此浏览器不支持此功能");
            }
        });
    },
    addreply: function(op, opt) {
        var _this = this;

        Chenxin.ajax({
            type: "post",
            dataType: "json",
            async: false,
            url: this.actionUrl,
            data: { op: 'addreply', subjects: $("#txtSubject").val(), contents: escape(this.editor.getSource()), recordid: $("#ctl00_main_hidRecordId").val(), rootid: $("#ctl00_main_hidRootId").val(), filename: op, savename: opt },
            onSuccess: function(data, msg) {
                alert(msg);
                $("#divreply").slideToggle("slow");
                $("#txtcontent").val('');
                if (_this.grid) {
                    _this.grid.reload();
                }
                if (this.afterDelSucc) {
                    _this.afterDelSucc.call(_this, data, msg);
                }
            }
        });
    },
    initComponent: function() {
        Chenxin.UI.WorkReportDetailInfo.superclass.initComponent.call(this);
    }
}); 

$(document).ready(function() {
    $('#aaa').hide();
    this.WorkReportDetailInfo=new Chenxin.UI.WorkReportDetailInfo();
});